package com.example.demo.controller;


import com.example.demo.read.ReadFile;
import com.example.demo.read.ReadFiles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * @author HadwinLing
 * @version V1.0
 * @Package com.nanhua.face.controller
 * @date 2020/11/14 13:57
 */
@Controller
public class ReadController {
    @Autowired
    private ReadFile readFile;

    private ReadFiles readFiles = new ReadFiles();

    @GetMapping("/")
    public String page(){
        return "index";
    }

   /* @PostMapping("/path")
    public void index(@RequestParam("file") String file) throws IOException {
        System.out.println("file:"+ file);
        readFile.readFile(file,"F:\\\\Test");
    }*/

    @PostMapping("/path")
    public void index(HttpServletRequest request, HttpServletResponse response) throws IOException {
        MultipartHttpServletRequest params=((MultipartHttpServletRequest) request);
        List<MultipartFile> files = params.getFiles("file");//file为文件项的name值
        for (int j = 0; j < files.size(); j++) {
//            System.out.println("FileName :  "+files.get(j).getOriginalFilename());
            readFiles.uploadFile(files.get(j),"F:\\\\Test");
        }
//        readFile.readFile(file,"F:\\\\Test");
    }
}
